package com.csht.service.Impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.csht.mapper.CshtGoodsReportMapper;
import com.csht.model.CshtGoodsReport;
import com.csht.page.PagerModel;
import com.csht.service.CshtGoodsReportService;
import com.csht.vo.my.CshtGoodsReportVo;

/**
 * 商品举报记录service
 * @author chenhuiyan
 *
 */
@Service
public class CshtGoodsReportServiceImpl implements CshtGoodsReportService {
	
	@Autowired
	private CshtGoodsReportMapper cshtGoodsReportMapper;

	/**
	 * 根据用户id查询用户举报记录总数
	 */
	@Override
	public Integer getGoodsReportNumberByUserId(Integer userId) throws Exception {
		Integer number = cshtGoodsReportMapper.getGoodsReportNumberByUserId(userId);
		return number;
	}

	/**
	 * 根据用户id查询用户举报记录（扩展类中扩展了商品，商品类中扩展对应的用户和商品图片）
	 */
	@Override
	public PagerModel<CshtGoodsReportVo> getGoodsReportByUserId(Map<String, Integer> res) throws Exception {
		List<CshtGoodsReportVo> cshtGoodsReportVoList = cshtGoodsReportMapper.getGoodsReportByUserId(res);
		Integer totalSize = cshtGoodsReportMapper.getGoodsReportNumberByUserId(res.get("userId"));
		Integer offset = res.get("offset");
		Integer messagePageSize = res.get("messagePageSize");
		PagerModel<CshtGoodsReportVo> pagerModelGoodsRepor = new PagerModel<CshtGoodsReportVo>();
		pagerModelGoodsRepor.setDates(cshtGoodsReportVoList);
		pagerModelGoodsRepor.setMessagePageSize(messagePageSize);
		pagerModelGoodsRepor.setOffset(offset);
		pagerModelGoodsRepor.setTotalSize(totalSize);
		return pagerModelGoodsRepor;
	}

	/**
	 * 根据举报记录id查询举报记录
	 */
	@Override
	public CshtGoodsReportVo getGoodsReportByGoodsReportId(Integer goodsReportId) throws Exception {
		CshtGoodsReportVo cshtGoodsReportVo = cshtGoodsReportMapper.getGoodsReportByGoodsReportId(goodsReportId);
		return cshtGoodsReportVo;
	}

	/**
	 * 插入记录
	 */
	@Override
	public void insertGoodsReport(CshtGoodsReport cshtGoodsReport) throws Exception {
		cshtGoodsReportMapper.insertGoodsReport(cshtGoodsReport);
	}

}
